<template>
    <div>
        <v-dialog
            title="接收"
            :show.sync="dialogVisible"
            @beforeClose="beforeClose"
            width="800px">
            <div><p>注：确认合同准确无误，点击审核通过生成合同应收；如果合同有误，点击退回租赁合同。</p></div>
            <span slot="foot">
                <el-button size="small" @click="returned">退回合同</el-button>
				<el-button size="small" @click="dialogVisible = false">取消</el-button>
				<el-button size="small" type="primary" @click="receive">确认接收</el-button>
          </span>
        </v-dialog>
    </div>
</template>

<script>
import {check,addReceive} from '../../../api/finance-collection-receivable'

import BaseLoad from '@/assets/vue-mixin/BaseLoad'
import {mapState} from 'vuex'
export default {
    mixins: [BaseLoad],
    data() {
        return {
            dialogVisible: false,
            form: {
                remarks: "",
                rentContractId: ""
            },
        }
    },
    methods: {
        show(item) {
            this.dialogVisible = true
            setTimeout(() => {
                if(item){
                    this.form.rentContractId = item.rentContractId
                }
            }, 200)
        },
        commit() {
            this.$refs.editForm.validate(valid => {
            })
        },
        beforeUpload() {
            this.loadAction('请稍等...')
        },
        returned() {
            this.$prompt('请填写退回原因', '退回原因', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /\S/,
                inputErrorMessage: '退回原因不能为空'
            }).then(({ value }) => {
                this.form.remarks = value
                addReceive(this.form).then(resp => {
                    if (resp.data.data) {
                        this.$message({
                            type: 'success',
                            message: '合同已退回经营部！'
                        });
                        this.dialogVisible = false;
                        this.$emit('resetList')
                        this.$emit('getTabListData')
                        this.$forceUpdate()
                    } else {
                        this.err('操作失败')
                    }
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '取消输入'
                });
            });
        },
        receive() {
            addReceive(this.form).then(resp => {
                if (resp.data.data) {
                    this.$message({
                        type: 'success',
                        message: '合同已接收！'
                    });
                    this.dialogVisible = false;
                    this.$emit('resetList')
                    this.$emit('clickCheck')
                    this.$emit('getTabListData')
                } else {
                    this.err('操作失败')
                }
            })
        },
        beforeClose(done) {
            done();
        }
    }
}
</script>

<style lang='scss' scoped>

@include data-title();
@include info-list(2);
@include formWrap(3);
</style>
